{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Copyright (c) 2020, NVIDIA CORPORATION.\n",
    "Licensed under the Apache License, Version 2.0 (the \"License\");\n",
    "you may not use this file except in compliance with the License.\n",
    "You may obtain a copy of the License at\n",
    "    http://www.apache.org/licenses/LICENSE-2.0\n",
    "Unless required by applicable law or agreed to in writing, software\n",
    "distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "See the License for the specific language governing permissions and\n",
    "limitations under the License."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd, time\n",
    "startNB = time.time()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Ensemble Public Test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tweet_id</th>\n",
       "      <th>b_user_id</th>\n",
       "      <th>prediction</th>\n",
       "      <th>reply</th>\n",
       "      <th>retweet</th>\n",
       "      <th>retweet_comment</th>\n",
       "      <th>like</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7647B4E9DAF4C1D8973397DC2A04F3E3</td>\n",
       "      <td>0000006C3074607050F1339DDCB890BB</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.031863</td>\n",
       "      <td>0.013925</td>\n",
       "      <td>0.003325</td>\n",
       "      <td>0.549908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>408DB1803264B5FF55F73EC06BE9BD77</td>\n",
       "      <td>000013315386492275CCBF7AEF293EF0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.002831</td>\n",
       "      <td>0.094954</td>\n",
       "      <td>0.002780</td>\n",
       "      <td>0.899267</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2EE951379C47E8BF62EABB8FA027F753</td>\n",
       "      <td>00001569CB28972FC8173122D9DA162F</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.014427</td>\n",
       "      <td>0.064910</td>\n",
       "      <td>0.004155</td>\n",
       "      <td>0.341107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2135F24B05DAE3EF213F9CE80FDC6DAF</td>\n",
       "      <td>00001607209C5774DF9207A2AC0EED5F</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.001251</td>\n",
       "      <td>0.048451</td>\n",
       "      <td>0.001705</td>\n",
       "      <td>0.572710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>09143FEDE9BD494A6EA9A7EE160565E3</td>\n",
       "      <td>0000177705514C315F2FC6DFA3872712</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.005884</td>\n",
       "      <td>0.031211</td>\n",
       "      <td>0.002068</td>\n",
       "      <td>0.205644</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           tweet_id                         b_user_id  \\\n",
       "0  7647B4E9DAF4C1D8973397DC2A04F3E3  0000006C3074607050F1339DDCB890BB   \n",
       "1  408DB1803264B5FF55F73EC06BE9BD77  000013315386492275CCBF7AEF293EF0   \n",
       "2  2EE951379C47E8BF62EABB8FA027F753  00001569CB28972FC8173122D9DA162F   \n",
       "3  2135F24B05DAE3EF213F9CE80FDC6DAF  00001607209C5774DF9207A2AC0EED5F   \n",
       "4  09143FEDE9BD494A6EA9A7EE160565E3  0000177705514C315F2FC6DFA3872712   \n",
       "\n",
       "   prediction     reply   retweet  retweet_comment      like  \n",
       "0         0.0  0.031863  0.013925         0.003325  0.549908  \n",
       "1         0.0  0.002831  0.094954         0.002780  0.899267  \n",
       "2         0.0  0.014427  0.064910         0.004155  0.341107  \n",
       "3         0.0  0.001251  0.048451         0.001705  0.572710  \n",
       "4         0.0  0.005884  0.031211         0.002068  0.205644  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# LOAD XGBoost3 FIRST\n",
    "sub = pd.read_parquet('../XGBoost3/sub_pub_1334_1.parquet')\n",
    "for k in range(2,6):\n",
    "    sub0 = pd.read_parquet('../XGBoost3/sub_pub_1334_%i.parquet'%k)\n",
    "    sub.iloc[:,3:] += sub0.iloc[:,3:].values\n",
    "sub.iloc[:,3:] /= 5.\n",
    "sub.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7647B4E9DAF4C1D8973397DC2A04F3E3</td>\n",
       "      <td>0000006C3074607050F1339DDCB890BB</td>\n",
       "      <td>0.025758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>408DB1803264B5FF55F73EC06BE9BD77</td>\n",
       "      <td>000013315386492275CCBF7AEF293EF0</td>\n",
       "      <td>0.002699</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2EE951379C47E8BF62EABB8FA027F753</td>\n",
       "      <td>00001569CB28972FC8173122D9DA162F</td>\n",
       "      <td>0.000016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2135F24B05DAE3EF213F9CE80FDC6DAF</td>\n",
       "      <td>00001607209C5774DF9207A2AC0EED5F</td>\n",
       "      <td>0.006969</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>09143FEDE9BD494A6EA9A7EE160565E3</td>\n",
       "      <td>0000177705514C315F2FC6DFA3872712</td>\n",
       "      <td>0.000004</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  0                                 1  \\\n",
       "0  7647B4E9DAF4C1D8973397DC2A04F3E3  0000006C3074607050F1339DDCB890BB   \n",
       "1  408DB1803264B5FF55F73EC06BE9BD77  000013315386492275CCBF7AEF293EF0   \n",
       "2  2EE951379C47E8BF62EABB8FA027F753  00001569CB28972FC8173122D9DA162F   \n",
       "3  2135F24B05DAE3EF213F9CE80FDC6DAF  00001607209C5774DF9207A2AC0EED5F   \n",
       "4  09143FEDE9BD494A6EA9A7EE160565E3  0000177705514C315F2FC6DFA3872712   \n",
       "\n",
       "          2  \n",
       "0  0.025758  \n",
       "1  0.002699  \n",
       "2  0.000016  \n",
       "3  0.006969  \n",
       "4  0.000004  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# LOAD XGBoost1 MODEL\n",
    "sub0 = pd.read_csv('../XGBoost1/submissions/xgb-final-retweet-public-1.csv',header=None)\n",
    "sub1 = pd.read_csv('../XGBoost1/submissions/xgb-final-reply-public-1.csv',header=None)\n",
    "sub2 = pd.read_csv('../XGBoost1/submissions/xgb-final-like-public-1.csv',header=None)\n",
    "sub3 = pd.read_csv('../XGBoost1/submissions/xgb-final-retweet_comment-public-1.csv',header=None)\n",
    "sub3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "wt1 = [0.8, 0.7, 1.0, 0.7]\n",
    "sub.retweet = (1-wt1[0]) * sub.retweet.values + wt1[0] * sub0.iloc[:,2].values\n",
    "sub.reply = (1-wt1[1]) * sub.reply.values + wt1[1] * sub1.iloc[:,2].values\n",
    "sub.like = (1-wt1[2]) * sub.like.values + wt1[2] * sub2.iloc[:,2].values\n",
    "sub.retweet_comment = (1-wt1[3]) * sub.retweet_comment.values + wt1[3] * sub3.iloc[:,2].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7647B4E9DAF4C1D8973397DC2A04F3E3</td>\n",
       "      <td>0000006C3074607050F1339DDCB890BB</td>\n",
       "      <td>0.005483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>408DB1803264B5FF55F73EC06BE9BD77</td>\n",
       "      <td>000013315386492275CCBF7AEF293EF0</td>\n",
       "      <td>0.000289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2EE951379C47E8BF62EABB8FA027F753</td>\n",
       "      <td>00001569CB28972FC8173122D9DA162F</td>\n",
       "      <td>0.000014</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2135F24B05DAE3EF213F9CE80FDC6DAF</td>\n",
       "      <td>00001607209C5774DF9207A2AC0EED5F</td>\n",
       "      <td>0.002063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>09143FEDE9BD494A6EA9A7EE160565E3</td>\n",
       "      <td>0000177705514C315F2FC6DFA3872712</td>\n",
       "      <td>0.000005</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  0                                 1  \\\n",
       "0  7647B4E9DAF4C1D8973397DC2A04F3E3  0000006C3074607050F1339DDCB890BB   \n",
       "1  408DB1803264B5FF55F73EC06BE9BD77  000013315386492275CCBF7AEF293EF0   \n",
       "2  2EE951379C47E8BF62EABB8FA027F753  00001569CB28972FC8173122D9DA162F   \n",
       "3  2135F24B05DAE3EF213F9CE80FDC6DAF  00001607209C5774DF9207A2AC0EED5F   \n",
       "4  09143FEDE9BD494A6EA9A7EE160565E3  0000177705514C315F2FC6DFA3872712   \n",
       "\n",
       "          2  \n",
       "0  0.005483  \n",
       "1  0.000289  \n",
       "2  0.000014  \n",
       "3  0.002063  \n",
       "4  0.000005  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# LOAD XGBoost2 MODEL\n",
    "sub0 = pd.read_csv('../XGBoost2/output/sub040/pub_retweet_x0.85.csv',header=None)\n",
    "sub1 = pd.read_csv('../XGBoost2/output/sub040/pub_reply_x0.85.csv',header=None)\n",
    "sub2 = pd.read_csv('../XGBoost2/output/sub040/pub_like_x0.85.csv',header=None)\n",
    "sub3 = pd.read_csv('../XGBoost2/output/sub040/pub_retweet_comment_x0.85.csv',header=None)\n",
    "sub3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "wt2 = [0.4, 0.5, 0.3, 0.6]\n",
    "sub.retweet = (1-wt2[0]) * sub.retweet.values + wt2[0] * sub0.iloc[:,2].values\n",
    "sub.reply = (1-wt2[1]) * sub.reply.values + wt2[1] * sub1.iloc[:,2].values\n",
    "sub.like = (1-wt2[2]) * sub.like.values + wt2[2] * sub2.iloc[:,2].values\n",
    "sub.retweet_comment = (1-wt2[3]) * sub.retweet_comment.values + wt2[3] * sub3.iloc[:,2].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# WRITE FILE\n",
    "for t in sub.columns[3:]:\n",
    "    sub[t] = sub[t].astype('float32')\n",
    "sub.to_parquet('submission_public.parquet',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub[['tweet_id','b_user_id','reply']].to_csv('public_sub_reply.csv',index=False,header=False)\n",
    "sub[['tweet_id','b_user_id','retweet']].to_csv('public_sub_retweet.csv',index=False,header=False)\n",
    "sub[['tweet_id','b_user_id','retweet_comment']].to_csv('public_sub_comment.csv',index=False,header=False)\n",
    "sub[['tweet_id','b_user_id','like']].to_csv('public_sub_like.csv',index=False,header=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Ensemble Private Test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tweet_id</th>\n",
       "      <th>b_user_id</th>\n",
       "      <th>prediction</th>\n",
       "      <th>reply</th>\n",
       "      <th>retweet</th>\n",
       "      <th>retweet_comment</th>\n",
       "      <th>like</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>04746004AA1F5498834CE7A4C6343D1A</td>\n",
       "      <td>00000776B07587ECA9717BFC301F2D6E</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.243955</td>\n",
       "      <td>0.006709</td>\n",
       "      <td>0.002323</td>\n",
       "      <td>0.917481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B5C4CBE185831F3E5A58A4D81118D4C7</td>\n",
       "      <td>00000776B07587ECA9717BFC301F2D6E</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.068159</td>\n",
       "      <td>0.197304</td>\n",
       "      <td>0.009618</td>\n",
       "      <td>0.913009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6B6836351BFAA6D1CC1EB0386BCB8C6A</td>\n",
       "      <td>00000B85AAF7DE172876FD96718C4469</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.007112</td>\n",
       "      <td>0.764966</td>\n",
       "      <td>0.091289</td>\n",
       "      <td>0.709978</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0DCF558E40500F22F84F98C4E7C38EDC</td>\n",
       "      <td>00000E0C9B364891CDE89ECFC54771DE</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.004229</td>\n",
       "      <td>0.081783</td>\n",
       "      <td>0.005452</td>\n",
       "      <td>0.415365</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>F13AA57F12DD6107D9D8544A27BDE9EC</td>\n",
       "      <td>0000109A57AFA64758EE4AAE2A01BFC7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.007811</td>\n",
       "      <td>0.015649</td>\n",
       "      <td>0.001693</td>\n",
       "      <td>0.108730</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           tweet_id                         b_user_id  \\\n",
       "0  04746004AA1F5498834CE7A4C6343D1A  00000776B07587ECA9717BFC301F2D6E   \n",
       "1  B5C4CBE185831F3E5A58A4D81118D4C7  00000776B07587ECA9717BFC301F2D6E   \n",
       "2  6B6836351BFAA6D1CC1EB0386BCB8C6A  00000B85AAF7DE172876FD96718C4469   \n",
       "3  0DCF558E40500F22F84F98C4E7C38EDC  00000E0C9B364891CDE89ECFC54771DE   \n",
       "4  F13AA57F12DD6107D9D8544A27BDE9EC  0000109A57AFA64758EE4AAE2A01BFC7   \n",
       "\n",
       "   prediction     reply   retweet  retweet_comment      like  \n",
       "0         0.0  0.243955  0.006709         0.002323  0.917481  \n",
       "1         0.0  0.068159  0.197304         0.009618  0.913009  \n",
       "2         0.0  0.007112  0.764966         0.091289  0.709978  \n",
       "3         0.0  0.004229  0.081783         0.005452  0.415365  \n",
       "4         0.0  0.007811  0.015649         0.001693  0.108730  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# LOAD XGBoost3 FIRST\n",
    "sub = pd.read_parquet('../XGBoost3/sub_priv_1334_1.parquet')\n",
    "for k in range(2,6):\n",
    "    sub0 = pd.read_parquet('../XGBoost3/sub_priv_1334_%i.parquet'%k)\n",
    "    sub.iloc[:,3:] += sub0.iloc[:,3:].values\n",
    "sub.iloc[:,3:] /= 5.\n",
    "sub.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>04746004AA1F5498834CE7A4C6343D1A</td>\n",
       "      <td>00000776B07587ECA9717BFC301F2D6E</td>\n",
       "      <td>0.001207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B5C4CBE185831F3E5A58A4D81118D4C7</td>\n",
       "      <td>00000776B07587ECA9717BFC301F2D6E</td>\n",
       "      <td>0.004615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6B6836351BFAA6D1CC1EB0386BCB8C6A</td>\n",
       "      <td>00000B85AAF7DE172876FD96718C4469</td>\n",
       "      <td>0.138609</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0DCF558E40500F22F84F98C4E7C38EDC</td>\n",
       "      <td>00000E0C9B364891CDE89ECFC54771DE</td>\n",
       "      <td>0.006942</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>F13AA57F12DD6107D9D8544A27BDE9EC</td>\n",
       "      <td>0000109A57AFA64758EE4AAE2A01BFC7</td>\n",
       "      <td>0.000853</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  0                                 1  \\\n",
       "0  04746004AA1F5498834CE7A4C6343D1A  00000776B07587ECA9717BFC301F2D6E   \n",
       "1  B5C4CBE185831F3E5A58A4D81118D4C7  00000776B07587ECA9717BFC301F2D6E   \n",
       "2  6B6836351BFAA6D1CC1EB0386BCB8C6A  00000B85AAF7DE172876FD96718C4469   \n",
       "3  0DCF558E40500F22F84F98C4E7C38EDC  00000E0C9B364891CDE89ECFC54771DE   \n",
       "4  F13AA57F12DD6107D9D8544A27BDE9EC  0000109A57AFA64758EE4AAE2A01BFC7   \n",
       "\n",
       "          2  \n",
       "0  0.001207  \n",
       "1  0.004615  \n",
       "2  0.138609  \n",
       "3  0.006942  \n",
       "4  0.000853  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# LOAD XGBoost1 MODEL\n",
    "sub0 = pd.read_csv('../XGBoost1/submissions/xgb-retweet-private-1.csv',header=None)\n",
    "sub1 = pd.read_csv('../XGBoost1/submissions/xgb-reply-private-1.csv',header=None)\n",
    "sub2 = pd.read_csv('../XGBoost1/submissions/xgb-like-private-1.csv',header=None)\n",
    "sub3 = pd.read_csv('../XGBoost1/submissions/xgb-retweet_comment-private-1.csv',header=None)\n",
    "sub3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub.retweet = (1-wt1[0]) * sub.retweet.values + wt1[0] * sub0.iloc[:,2].values\n",
    "sub.reply = (1-wt1[1]) * sub.reply.values + wt1[1] * sub1.iloc[:,2].values\n",
    "sub.like = (1-wt1[2]) * sub.like.values + wt1[2] * sub2.iloc[:,2].values\n",
    "sub.retweet_comment = (1-wt1[3]) * sub.retweet_comment.values + wt1[3] * sub3.iloc[:,2].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>04746004AA1F5498834CE7A4C6343D1A</td>\n",
       "      <td>00000776B07587ECA9717BFC301F2D6E</td>\n",
       "      <td>0.000966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B5C4CBE185831F3E5A58A4D81118D4C7</td>\n",
       "      <td>00000776B07587ECA9717BFC301F2D6E</td>\n",
       "      <td>0.005360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6B6836351BFAA6D1CC1EB0386BCB8C6A</td>\n",
       "      <td>00000B85AAF7DE172876FD96718C4469</td>\n",
       "      <td>0.091135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0DCF558E40500F22F84F98C4E7C38EDC</td>\n",
       "      <td>00000E0C9B364891CDE89ECFC54771DE</td>\n",
       "      <td>0.005561</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>F13AA57F12DD6107D9D8544A27BDE9EC</td>\n",
       "      <td>0000109A57AFA64758EE4AAE2A01BFC7</td>\n",
       "      <td>0.001984</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  0                                 1  \\\n",
       "0  04746004AA1F5498834CE7A4C6343D1A  00000776B07587ECA9717BFC301F2D6E   \n",
       "1  B5C4CBE185831F3E5A58A4D81118D4C7  00000776B07587ECA9717BFC301F2D6E   \n",
       "2  6B6836351BFAA6D1CC1EB0386BCB8C6A  00000B85AAF7DE172876FD96718C4469   \n",
       "3  0DCF558E40500F22F84F98C4E7C38EDC  00000E0C9B364891CDE89ECFC54771DE   \n",
       "4  F13AA57F12DD6107D9D8544A27BDE9EC  0000109A57AFA64758EE4AAE2A01BFC7   \n",
       "\n",
       "          2  \n",
       "0  0.000966  \n",
       "1  0.005360  \n",
       "2  0.091135  \n",
       "3  0.005561  \n",
       "4  0.001984  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# LOAD XGBoost2 MODEL\n",
    "sub0 = pd.read_csv('../XGBoost2/output/sub040/pvt_retweet_x0.85.csv',header=None)\n",
    "sub1 = pd.read_csv('../XGBoost2/output/sub040/pvt_reply_x0.85.csv',header=None)\n",
    "sub2 = pd.read_csv('../XGBoost2/output/sub040/pvt_like_x0.85.csv',header=None)\n",
    "sub3 = pd.read_csv('../XGBoost2/output/sub040/pvt_retweet_comment_x0.85.csv',header=None)\n",
    "sub3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub.retweet = (1-wt2[0]) * sub.retweet.values + wt2[0] * sub0.iloc[:,2].values\n",
    "sub.reply = (1-wt2[1]) * sub.reply.values + wt2[1] * sub1.iloc[:,2].values\n",
    "sub.like = (1-wt2[2]) * sub.like.values + wt2[2] * sub2.iloc[:,2].values\n",
    "sub.retweet_comment = (1-wt2[3]) * sub.retweet_comment.values + wt2[3] * sub3.iloc[:,2].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# WRITE FILE\n",
    "for t in sub.columns[3:]:\n",
    "    sub[t] = sub[t].astype('float32')\n",
    "sub.to_parquet('submission_private.parquet',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub[['tweet_id','b_user_id','reply']].to_csv('private_sub_reply.csv',index=False,header=False)\n",
    "sub[['tweet_id','b_user_id','retweet']].to_csv('private_sub_retweet.csv',index=False,header=False)\n",
    "sub[['tweet_id','b_user_id','retweet_comment']].to_csv('private_sub_comment.csv',index=False,header=False)\n",
    "sub[['tweet_id','b_user_id','like']].to_csv('private_sub_like.csv',index=False,header=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Elapsed Time is 5.787362 minutes\n"
     ]
    }
   ],
   "source": [
    "print('Elapsed Time is %f minutes'%((time.time()-startNB)/60))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
